import React, { Component } from 'react'
import Message from './Message'
import ProductList from './ProductList'
import axios from 'axios'

class App extends Component {
  constructor() {
    super()
    this.state = {
      count: 1,
      products: []
    }
  }
  changeCount() {
    this.setState({
      count: this.state.count + 1
    })
  }
  componentDidMount() {
    axios.get('https://jsonplaceholder.typicode.com/todos').then(res => {
      this.setState({
        products: res.data
      })
    })
  }
  render() {
    const { count, products } = this.state
    return (
      <div>
        <button onClick={() => this.changeCount()}>count+1</button>
        <Message count={count} />
        <Message />
        <ProductList products={products} />
      </div>
    )
  }
}

export default App